# Copyright 2001,2002,2003 NAH6
# All Rights Reserved
# 
# Parts Copyright DoD, Parts Copyright Starium
# 

## "codec/celp_fxp/gcc/Makefile"

# commandline defs:
#    target=arm   or target=x86
#    CB=64, ... CB=512
#
#    if no CB is specified then 128 is used ( experimentally found to be 
#    the largest workable value on a 206Mhz SA1110
#
ifndef target
	target=arm
endif

ifeq ($(target),arm)
	CC	=	arm-coff-gcc
	AS	=	arm-coff-as
	LD	=	arm-coff-ld
	TGTFLAGS= -mcpu=strongarm1100 
else 
ifeq ($(target),x86)
	CC	=	gcc
	AS	=	as
	LD	=	ld
	TGTFLAGS= -mhard-float 
else
# echo does not really work, but makefile will terminate any way now.
	echo "ERROR: no target set ( choose arm or x86 )"
	exit
endif
endif

ifdef CB
CDEFS= -DSTOCH_CB_SIZE=$(CB)
endif

# [bigmac]: POSTFILTER does not work well for this fixedpoint version
BUILDDEF= -DDURBIN -DNEW_LSF_CODE -DNEW_ACB -DSTREAMLINE
#BUILDDEF= -DDURBIN -DNEW_LSF_CODE -DNEW_ACB -DPOSTFILTER


CFLAGS	= -Wall -fno-strict-aliasing -Wall -pipe -DNDEBUG \
		$(BUILDDEF) $(TGTFLAGS) $(CDEFS)  \
		-O3   -D_USE_INLINED_FXPT \
		-fomit-frame-pointer -DSTATIC=static

# add '-pg -DSTATIC=' for profiling 
# add '-g' for debugging
# add '-O3 -fomit-frame-pointer -DSTATIC=static' for more optimization.

#  -D__NO_INLINE__
INC	=	-I. -I/usr/include
OBJ	=	./$(target)
PRE	=	./pre
ASM	=	./$(target)asm
RM	=	rm -f

SOURCES= \
	celp.c acb_code.c acb_parm.c adapt.c analysis.c auto_cor.c bwexp.c calc_adapt_conv.c calc_cor_eng_adapt.c \
	calc_cor_eng_stoch.c calc_stoch_conv.c celp_sup.c code_lsf.c codeparm.c con_adap.c con_stch.c conv_cor.c \
	delay.c do_pfilt.c do_pfilt2.c do_pfilt_dynamic.c do_pfilt_dynamic32to16.c do_zfilt.c do_zfilt2.c \
	do_zfilt_dynamic16to32.c do_zfilt_dynamic32to32.c end_correct_adapt.c end_correct_stoch.c error.c filters.c \
	fxpt_div.c fxpt_sine16.c hamming.c integer_sqrt.c interp.c lp_anal.c lp_syn.c lsftopc.c makefilt.c mexcite.c \
	move_array16.c pctolsf.c pctorc.c postfilt.c replicate_short_to_full_calc_cor_eng_adapt.c resample_long.c \
	resample_short.c scb_code.c setup.c stoch.c synth.c zero_array16.c fxpt.c

PRESOURCES= $(SOURCES:.c=.B)
OBJECTS= $(SOURCES:.c=.o)
ASMSOURCES= $(SOURCES:.c=.S)


#$(OBJ)/%.o: $(ASM)/%.S
#	$(CC) -c $(CFLAGS) $(INC) -o $@ $<

$(PRE)/%.B: %.c
	$(CC) -E $(CFLAGS) $(INC) -o $@ $<

$(ASM)/%.S: %.c
	$(CC) -S -fverbose-asm $(CFLAGS) $(INC) -o $@ $<

$(OBJ)/%.o: %.c
	$(CC) -c $(CFLAGS) $(INC) -o $@ $<

obj: $(addprefix $(OBJ)/,$(OBJECTS))

asm: $(addprefix $(ASM)/,$(ASMSOURCES))

pre: $(addprefix $(PRE)/,$(PRESOURCES))

test: obj $(OBJ)/celptest.o
	$(CC) -g -o test $(OBJ)/*.o

